package com.hllxd.hism.star.basic.service.controller2;

import com.hllxd.hism.framework.httprpc.service.*;
import com.hllxd.hism.star.basic.service.exception.BusinessException;
import com.hllxd.hism.star.basic.service.service.OpenaiService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 计算任务白名单管理
 * @author xiyong.lxy
 * @date 2020-10-12 16:51
 */
@Slf4j
@RestGrpcService
@RestGrpcMapping("/v1/openai")
public class OpenaiController2 {

    @Autowired
    private OpenaiService openaiService;

    @Data
    public static class Param {
        public Long id;
        /** 手机号 */
        public String question;
    }

    @RestGrpcMapping("/questionHandle.do")
    public NTSTATUS questionHandle(PDRIVER_OBJECT params, PRESULT_OBJECT result) {
        log.info("request params: {}", params);
        try {
            Param aa = params.driverObject(Param.class);
            result.setData(openaiService.questionHandle(aa.question));
            return NTSTATUS.SUCCESS_STATUS();
        }catch (BusinessException e) {
            log.warn("Exception: {}. {}",e.toString(), params);
            return NTSTATUS.ERROR_STATUS(e.code, e.msg);
        }catch (Exception e) {
            log.error("Exception: {}. {}", e.toString(), params, e);
            return NTSTATUS.ERROR_STATUS("500", e.toString());
        }
    }
}
